import React from 'react';
import type { FormProps } from 'antd';
import { Button, Checkbox, Form, Input } from 'antd';
import axios from 'axios'
import { useNavigate } from 'react-router-dom';

function index() {
  type FieldType = {
    username?: string;
    password?: string; 
  };
  const nav=useNavigate()
  const onFinish: FormProps<FieldType>['onFinish'] =async (values) => {
    console.log('Success:', values);
    const res=await axios.post('/api/login',values)
    console.log(res)
    localStorage.setItem('name',res.data.username)
    nav('/')
  };
   
  return (
    <div>
      <Form
    name="basic"
    labelCol={{ span: 8 }}
    wrapperCol={{ span: 16 }}
    style={{ maxWidth: 600 }}
    initialValues={{ remember: true }}
    onFinish={onFinish} 
    autoComplete="off"
  >
    <Form.Item<FieldType>
      label="名称"
      name="account"
      rules={[{ required: true, message: 'Please input your 名称!' }]}
    >
      <Input />
    </Form.Item>

    <Form.Item<FieldType>
      label="密码"
      name="password"
      rules={[{ required: true, message: 'Please input your 密码!' }]}
    >
      <Input.Password />
    </Form.Item> 

    <Form.Item label={null}>
      <Button type="primary" htmlType="submit">
        登录
      </Button>
    </Form.Item>
  </Form>
    </div>
  )
}

export default index
